/*
 * @lc app=leetcode.cn id=724 lang=typescript
 *
 * [724] 寻找数组的中心下标
 */

// @lc code=start
function pivotIndex(nums: number[]): number {
    const count = nums.reduce((a, b) => b + a);
    let left = 0;
    let right = count;
    let i = 0;
    while (i < nums.length) {
        right -= nums[i];
        if (right === left) return i;
        left += nums[i];
        i++;
    }
    return -1;
}
// @lc code=end
